package com.java.day05.homework;

import java.util.Scanner;

/**
 * 菜单类
 */
public class Menu {
    UserRegister userRegister = new UserRegister();

    /**
     * 方法:
     * selectMenu 选择界面
     */

    public void selectMenu() {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请选择你要的功能:1.注册\t2.登录\t3.退出");
            String option = scanner.next();
            switch (option) {
                case "1":
                    System.out.println("请输入用户名:");
                    String userName = scanner.next();
                    System.out.println("请输入密码:");
                    String password = scanner.next();
                    System.out.println("请输入确认密码:");
                    userRegister.confirmWord= scanner.next();

                    if (userRegister.input(userName, password)==3) {
                        System.out.println("注册成功");
                    } else {
                        if(userRegister.input(userName, password)==1){
                            System.out.println("注册失败,用户重名");
                        }
                        if(userRegister.input(userName, password)==2){
                            System.out.println("密码和确认密码不一致");
                        }
                    }
                    break;
                case "2":
                    System.out.println("请输入用户名:");
                    String loginUserName = scanner.next();
                    System.out.println("请输入密码:");
                    String loginPassword = scanner.next();

                    if(userRegister.login(loginUserName,loginPassword)){
                        System.out.println("登录成功");
                    }else{
                        if(!userRegister.nameArrUtils(loginUserName)){
                            System.out.println("登录失败,请注册");
                        }else{
                            System.out.println("登录失败,用户名或密码错误");
                        }
                    }
                    break;
                case "3":
                    System.out.println("欢迎下次使用,886");
                    return;
                default:
                    System.out.println("输入错误");
            }
        }

    }

}
